package handler

import (
	"github.com/go-playground/validator/v10"
	"sgo/common/response"
	"sgo/scontext"
	"strings"
)

type ValidationErrorHandler struct{}

// 处理数据校验的异常信息
// 返回信息为中文提示

func (ValidationErrorHandler) handleError(sc *scontext.SgoContext, err error) response.Response {
	errs := err.(validator.ValidationErrors)
	var sliceErrs []string
	for _, e := range errs {
		sliceErrs = append(sliceErrs, e.Translate(*sc.Validator.Trans))
	}
	return response.FailWithMessage(strings.Join(sliceErrs, ","))
}
